package net.WMisiedjan.RedstoneEffects;

import java.beans.Beans;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.filechooser.FileFilter;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.introspector.BeanAccess;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;

public class RedstoneEffectsConf extends org.bukkit.util.config.Configuration {
	private StackableLogger logger;
	private File configFile;

	public RedstoneEffectsConf(File dataFolder) {
		super(new File(dataFolder, "settings.yml"));
		this.configFile = new File(dataFolder, "settings.yml");
		if (this.root == null) {
			this.root = new HashMap<String, Object>();
		}
		
		logger = RedstoneEffects.getLogger();
	}

	@Override
	public void load() {
		this.
		configFile = configFile.getAbsoluteFile();
		if (!configFile.getParentFile().exists()) {
			if (!configFile.getParentFile().mkdirs()) {
				logger.severe("Error creating folders for Configuration.");
			}
		}
		if (!configFile.exists()) {
			try {
				logger.info("Creating empty config file. Loading default settings.");
				if (!configFile.createNewFile()) {
					logger.severe("Failed to create config file.");
				}
				GenerateDefaults();
			} catch (IOException ex) {
				logger.severe("Failed to create config file.");
			}
		}

		super.load();
		if (this.root == null) {
			this.root = new HashMap<String, Object>();
		}
	}

	private void GenerateDefaults() {
		this.setProperty("LogLevel", Level.INFO.getName().toUpperCase());
		this.save();
	}

	public Level getLogLevel() {
		return Level.parse(this.getString("LogLevel"));
	}
}
